package com.yj.generator.constants;


import com.yj.generator.core.SqlExecutor;
import freemarker.template.Configuration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author DengLin
 * @title 配置常量
 * @date 2024/07/04
 */
public class ConfigConstant {
    private static final Logger log = LogManager.getLogger(ConfigConstant.class);

    public static final String JAVA_FILE_PATH = "src" + File.separator + "main" + File.separator + "java" + File.separator;
    public static final String CONFIG_PROPERTIES_PATH = "src/main/resources/config.properties";
    public static final String TEMPLATE_PATH = "src/main/resources/templates";
    public static final String DATASOURCE_URL = "datasource.url";
    public static final String DATASOURCE_USERNAME = "datasource.username";
    public static final String DATASOURCE_PASSWORD = "datasource.password";
    public static final String DATASOURCE_DRIVER = "datasource.driver";
    public static final String GENERATE_TABLES = "generate.tables";
    public static final String GENERATE_TABLE_PREFIX = "generate.table.prefix";
    public static final String GENERATE_TABLE_IGNORE_PREFIX = "generate.table.ignore-prefix";
    public static final String GENERATE_OUT_AUTHOR = "generate.out.author";
    public static final String GENERATE_OUT_PATH = "generate.out.path";
    public static final String GENERATE_OUT_PACKAGE = "generate.out.package";
    public static final String GENERATE_OUT_ENTITY_MODULE = "generate.out.entity";
    public static final String GENERATE_OUT_MAPPER_MODULE = "generate.out.mapper";
    public static final String GENERATE_OUT_SERVICE = "generate.out.service";
    public static final String GENERATE_OUT_CONTROLLER = "generate.out.controller";

    public static final List<String> IGNORE_DIM_FIELDS = new ArrayList<>();

    public static Configuration CONFIGURATION = new Configuration(Configuration.VERSION_2_3_31);

    static {

        IGNORE_DIM_FIELDS.add("create_time");
        IGNORE_DIM_FIELDS.add("update_time");
        IGNORE_DIM_FIELDS.add("del_flag");
        IGNORE_DIM_FIELDS.add("id");

        try {
            CONFIGURATION.setDirectoryForTemplateLoading(new File(ConfigConstant.TEMPLATE_PATH));
            CONFIGURATION.setDefaultEncoding("utf-8");
        } catch (IOException e) {
            log.error("读取模板文件夹失败:{}", e.getMessage());
        }
    }
}
